//
//  Scene_Setting.m
//  StarBugs
//
//  Created by ?? ? on 6/25/12.
//  Copyright 2012 antisword@playorca.com. All rights reserved.
//

#include "Scene/Scene_Setting.h"
#include "Scene/Scene_MainMenu.h"
#include "Util/ModuleController.h"
#include "Util/ImageManager.h"
#include "Util/Util.h"
#include "Util/DataBase.h"
#include "Layer/FadeActionLayer.h"
#include "Util/SoundManager.h"
#include "Util/UserData.h"
#include "Global.h"
using namespace cocos2d;

#define URL_EULA        "http://tos.ea.com/legalapp/mobileeula/US/en/OTHER/"
#define URL_PRIVACY     "http://tos.ea.com/legalapp/WEBPRIVACY/US/en/PC/"
#define URL_TERMS       "http://tos.ea.com/legalapp/WEBTERMS/US/en/PC/"

#define CREDIT_LINE_H   18
enum{
    kTag_background,
    kTag_layer,
    kTag_aboutBack,
    kTag_backbutton,
    kTag_frame,
    kTag_fade,
};



const char *creditTxt[] = 
{

    "Bumpy Space Ver.%s",
    "",
    "Copyright 2012 by Orca Inc.",
    "",
#ifdef __IOS_
    "A game developed by Orca Inc and",
    "published by Chillingo",
    "",
#endif
    "- ORCA -",
    "[Producer and Programer]",
    "Ray Jung",
    "",
    "[Graphic Artist]",
    "Boyeon Cho",
    "",
    "[Level Designer]",
    "Sancho",
    "",
    "[Music and Sound Designer]",
    "Audio4game",
    "",
    "[Quality Assurance]",
    "Peter Huh, Claire Cho",
    "",
    "[Spacial Thanks]",
    "Eunae Hwang, Chris Yu, Alex kwak, Sam Youn",
    "Daniel Kim, Jaemyung Jung, Soojung Bae",
    "Woochang Yang, Miji Kim",
    "People of Earth",
    "",
#ifdef __IOS_
    "- CHILLINGO -",
    "",
#endif
    "!",
    
};




CCScene* Scene_Setting::scene()
{
//    // 'scene' is an autorelease object
//    CCScene *scene = CCScene::create();
//    
//    // add layer as a child to scene
//    CCLayer* layer = new Scene_Setting();
//    scene->addChild(layer);
//    layer->release();
//    
//    return scene;
    CCLayer* layer = new Scene_Setting();
    layer->autorelease();
    return (CCScene *)layer;
}

Scene_Setting::~Scene_Setting()
{   
    ImageManager::closeXml(kImagesheet_setting);
    ImageManager::closeXml(kImageSheet_pauseSource);
    ImageManager::closeXml(kImageSheet_chapterSpace);
    
    if(aboutArray)
    {
        aboutArray->removeAllObjects();
        aboutArray->release();
        aboutArray = NULL;
    }
    CCTextureCache::sharedTextureCache()->removeUnusedTextures();
}

Scene_Setting::Scene_Setting()
{
    CCSize winSize = CCDirector::sharedDirector()->getWinSize();
    CCTextureCache::sharedTextureCache()->removeUnusedTextures();
    ImageManager::openXml(kImagesheet_setting);
    ImageManager::openXml(kImageSheet_pauseSource);
    ImageManager::openXml(kImageSheet_chapterSpace);

    
    setContentSize(CCSize(320 * ModuleController::getImageScale(), 480 * ModuleController::getImageScale()));
//    setPosition(ccp(winSize.width/2 - getContentSize().width/2, winSize.height/2 - getContentSize().height/2));
    setAnchorPoint(ccp(0, 0));
    setScale(ModuleController::getScaleFactor_h());
    
//    mainLayer = CCLayer::create();
//    mainLayer->setContentSize(CCSize(320 * ModuleController::getImageScale(), 480 * ModuleController::getImageScale()));
//    mainLayer->setPosition(ccp(winSize.width/2 - mainLayer->getContentSize().width/2, winSize.height/2 - mainLayer->getContentSize().height/2));
//    mainLayer->setScale(ModuleController::getScaleFactor());

//    mainLayer = CCLayerColor::create(ccc4(255, 0, 0, 255), 320 * ModuleController::getImageScale(), 480 * ModuleController::getImageScale());
//    mainLayer->setPosition(ccp(winSize.width/2 - 160, winSize.height/2 - 240));
//    mainLayer->setScale(2.0);
    
    
    setTouchEnabled(true);
    
    isBgPlay = Database::getInstancePtr()->gameDatabase.isBgSound;
    isEffPlay = Database::getInstancePtr()->gameDatabase.isEffSound;

    winSize = CCDirector::sharedDirector()->getWinSize();
//    CCTexture2D::setDefaultAlphaPixelFormat(kCCTexture2DPixelFormat_RGB565);
    CCSprite *backSprite = CCSprite::create("bg_space.png");
    backSprite->setAnchorPoint(ccp(0.5, 0.5));
    backSprite->setPosition(ccp(160, 240));
    addChild(backSprite, kTag_background);
    
    if(ModuleController::getIs5())
    {
        CCSprite *sprite = CCSprite::create("bg_space_1136_1.png");
        sprite->setAnchorPoint(ccp(0,0));
        sprite->setPosition(ccp(0, 480));
        backSprite->addChild(sprite);
    }
    
//    CCTexture2D::setDefaultAlphaPixelFormat(kCCTexture2DPixelFormat_Default);
   
    
    button_back = ImageManager::getSpriteWithXml2(kImagesheet_setting, "back");
    button_back->setPosition(ccp(40, 30));
    addChild(button_back, kTag_backbutton);
    
    addSettingLayer();
    addCreditsLayer();
    addInfoLayer();
    
    changeSettingState(settingState_init);
    addChild(FadeActionLayer::getInstancePtr(), kTag_fade);
    
    aboutArray = CCArray::create();
    aboutArray->retain();

//    if(ModuleController::getIsIpad())
//    {
//        CCLayerColor *layer = CCLayerColor::create(ccc4(0, 0, 0, 255), 44, 960);
//        layer->setPosition(ccp(-44, 0));
//        addChild(layer, kTag_frame);
//        
//        layer = CCLayerColor::create(ccc4(0, 0, 0, 255), 44, 960);
//        layer->setPosition(ccp(640, 0));
//        addChild(layer, kTag_frame);
//    }
                                                                      
    
    schedule(schedule_selector(Scene_Setting::tick));
}

void Scene_Setting::tick(float dt)
{
    switch (settingState) {
        case settingState_init:
            if(FadeActionLayer::getInstancePtr()->getActionEndFlg())
            {
                changeSettingState(settingState_normal);
            }
            break;
        case settingState_gotoMainmenu:
            if(FadeActionLayer::getInstancePtr()->getActionEndFlg())
            {
                removeChild(FadeActionLayer::getInstancePtr(), false);
                UserData::getInstencePtr()->scene = scenenum_setting;
                CCDirector::sharedDirector()->replaceScene(Scene_MainMenu::scene());
            }
            break;
        case settingState_gotoAbout:
            if(FadeActionLayer::getInstancePtr()->getActionEndFlg())
            {
                changeSettingState(settingState_about);
            }
            break;
        case settingState_gotoInfo:
            if(FadeActionLayer::getInstancePtr()->getActionEndFlg())
            {
                changeSettingState(settingState_info);
            }
            break;
        case settingState_gotoSetting:
            if(FadeActionLayer::getInstancePtr()->getActionEndFlg())
            {
                changeSettingState(settingState_init);
            }
            break;
        case settingState_about:
            if(creditMoveLayer->getPosition().y > (480 + CREDIT_LINE_H * creditCnt) * ModuleController::getImageScale())
            {
                creditMoveLayer->setPosition(ccp(0, 0)); 
                creditMoveLayer->stopAllActions();
                CCMoveBy *move = CCMoveBy::create(1, ccp(0, 30 * ModuleController::getImageScale()));
                creditMoveLayer->runAction(CCRepeatForever::create(move));
            }
            break;
    }
}

void Scene_Setting::addSettingLayer()
{
    settingLayer = CCLayer::create();
    settingLayer->setPosition(ccp(0, (ModuleController::getSceneH() - 480)/2));
    
    addChild(settingLayer, kTag_layer);
    
    CCSprite *sprite;
    
    sprite = ImageManager::getSpriteWithXml2(kImagesheet_setting, "soundoption");
    sprite->setPosition(ccp(160, 425));
    settingLayer->addChild(sprite);
    
    if(isBgPlay)
        button_bg = ImageManager::getSpriteWithXml2(kImagesheet_setting, "bg_on");
    else
        button_bg = ImageManager::getSpriteWithXml2(kImagesheet_setting, "bg_off");
    
    button_bg->setPosition(ccp(100, 345));
    settingLayer->addChild(button_bg);
    
    if(isEffPlay)
        button_effect = ImageManager::getSpriteWithXml2(kImagesheet_setting, "eff_on");
    else
        button_effect = ImageManager::getSpriteWithXml2(kImagesheet_setting, "eff_off");
    button_effect->setPosition(ccp(220, 345));
    settingLayer->addChild(button_effect);
    
    sprite = ImageManager::getSpriteWithXml2(kImagesheet_setting, "bg");
    sprite->setPosition(ccp(100, 305));
    settingLayer->addChild(sprite);
    
    sprite = ImageManager::getSpriteWithXml2(kImagesheet_setting, "effect");
    sprite->setPosition(ccp(220, 305));
    settingLayer->addChild(sprite);
    
    sprite = ImageManager::getSpriteWithXml2(kImagesheet_setting, "line");
    sprite->setPosition(ccp(160, 260));
    settingLayer->addChild(sprite);
    
    button_about = ImageManager::getSpriteWithXml2(kImagesheet_setting, "about");
    button_about->setPosition(ccp(160, 210));
    settingLayer->addChild(button_about);
    
    button_info = ImageManager::getSpriteWithXml2(kImagesheet_setting, "info");
    button_info->setPosition(ccp(160, 140));
    settingLayer->addChild(button_info);
    
    button_restore = ImageManager::getSpriteWithXml2(kImagesheet_setting, "restore");
    button_restore->setPosition(ccp(160, 70));
    settingLayer->addChild(button_restore);
    
//    sprite = ImageManager::getSpriteWithXml2(kImageSheet_pauseSource, "box");
//    sprite->setAnchorPoint(CCPointZero);
//    sprite->setPosition(ccp(0, -50));
//    settingLayer->addChild(sprite);
}

void Scene_Setting::addCreditsLayer()
{
    creditsLayer = CCLayer::create();
    addChild(creditsLayer, kTag_layer);
    creditsLayer->setVisible(false);
    creditsLayer->setPosition(ccp(0, (ModuleController::getSceneH() - 480)/2));
    
    creditMoveLayer = CCLayer::create();
    creditMoveLayer->setPosition(ccp(0, 380));
    creditsLayer->addChild(creditMoveLayer, 0);
    
    CCSprite *backSprite = CCSprite::create("bg_space.png", CCRect(0, 0, 420*ModuleController::getImageScale(), 100*ModuleController::getImageScale()));
    backSprite->setAnchorPoint(ccp(0.5, 0));
    backSprite->setPosition(ccp(160, 380));
    creditsLayer->addChild(backSprite, 1);
    
    
    backSprite = CCSprite::create("bg_space.png", CCRect(0, (480 - 50) *ModuleController::getImageScale(), 420*ModuleController::getImageScale(), 50 *ModuleController::getImageScale()));
    backSprite->setAnchorPoint(ccp(0.5, 0));
    backSprite->setPosition(ccp(160, (480 - ModuleController::getSceneH())/2));
    creditsLayer->addChild(backSprite, 1);
    
    CCSprite *sprite;
    sprite = ImageManager::getSpriteWithXml2(kImageSheet_chapterSpace, "planet1");
    sprite->setPosition(ccp(17, 362));
    creditsLayer->addChild(sprite, 1);
    
    sprite = ImageManager::getSpriteWithXml2(kImageSheet_chapterSpace, "planet3");
    sprite->setPosition(ccp(280, 15));
    creditsLayer->addChild(sprite, 1);
    
    
    sprite = ImageManager::getSpriteWithXml2(kImagesheet_setting, "orca");
    sprite->setPosition(ccp(160, 420));
    creditsLayer->addChild(sprite, 1);
    
    sprite = ImageManager::getSpriteWithXml2(kImagesheet_setting, "line");
    sprite->setPosition(ccp(160, 380));
    creditsLayer->addChild(sprite, 1);
    
    
    CCLabelTTF *label;
    int i = 0;
    int fontSize = 0;
    while (true) {
        if(creditTxt[i][0] == '!')
            break;
        
        ccColor3B color = ccc3(255, 255, 255);
        
        fontSize = 14 * ModuleController::getImageScale();
        
        
        if(i == 0)
        {
            fontSize = 18 * ModuleController::getImageScale();
            char txt[64];
            sprintf(txt, creditTxt[i], _VERSION);
            label = CCLabelTTF::create(txt, "nanumgothicbold.ttf", fontSize);
        }
        else
        {
//            if(i == 0)
//                fontSize = 16;
            if(creditTxt[i][0] == '[')
                color = ccc3(255, 0, 0);
            else if(creditTxt[i][0] == '-')
            {
                color = ccc3(0, 0, 255);
                fontSize = 16 * ModuleController::getImageScale();
            }
            
            label = CCLabelTTF::create(creditTxt[i], "nanumgothicbold.ttf", fontSize);
        }
        label->setAnchorPoint(ccp(0.5, 1));
        creditMoveLayer->addChild(label);
        label->setPosition(ccp(160, -i * CREDIT_LINE_H));
        label->setColor(color);
        i++;
    }
    creditCnt = i;
    
    if(ModuleController::getIs5())
    {
        CCSprite *sprite = CCSprite::create("bg_space_1136_1.png");
        sprite->setAnchorPoint(ccp(0,0));
        sprite->setPosition(ccp(0, 480));
        creditsLayer->addChild(sprite);
    }
    
}

void Scene_Setting::addInfoLayer()
{
    infoLayer = CCLayer::create();
    addChild(infoLayer, kTag_layer);
    infoLayer->setVisible(false);
    infoLayer->setPosition(ccp(0, (ModuleController::getSceneH() - 480)/2));
    CCSprite *sprite;
    
    sprite = ImageManager::getSpriteWithXml2(kImageSheet_chapterSpace, "planet1");
    sprite->setPosition(ccp(200, 10));
    infoLayer->addChild(sprite);
    
    sprite = ImageManager::getSpriteWithXml2(kImageSheet_chapterSpace, "planet4");
    sprite->setPosition(ccp(300, 144));
    infoLayer->addChild(sprite);
    
    sprite = ImageManager::getSpriteWithXml2(kImageSheet_chapterSpace, "galaxy1");
    sprite->setPosition(ccp(41, 445));
    infoLayer->addChild(sprite);
    
    sprite = ImageManager::getSpriteWithXml2(kImagesheet_setting, "txt");
    sprite->setPosition(ccp(160, 400));
    infoLayer->addChild(sprite);
    
    button_eula = ImageManager::getSpriteWithXml2(kImagesheet_setting, "eula");
    button_eula->setPosition(ccp(160, 285));
    infoLayer->addChild(button_eula);
    
    button_privacy = ImageManager::getSpriteWithXml2(kImagesheet_setting, "privacy");
    button_privacy->setPosition(ccp(160, 205));
    infoLayer->addChild(button_privacy);
    
    button_terms = ImageManager::getSpriteWithXml2(kImagesheet_setting, "terms");
    button_terms->setPosition(ccp(160, 125));
    infoLayer->addChild(button_terms);
                             
}

void Scene_Setting::setBgSound()
{
    settingLayer->removeChild(button_bg, true);
    isBgPlay = !isBgPlay;
    
    SoundManager::muteSoundBgm(isBgPlay);
    if(isBgPlay)
    {
        button_bg = ImageManager::getSpriteWithXml2(kImagesheet_setting, "bg_on");
        SoundManager::PlaySoundBgm(bgm_1);
    }
    else
        button_bg = ImageManager::getSpriteWithXml2(kImagesheet_setting, "bg_off");
    
    button_bg->setPosition(ccp(100, 345));
    settingLayer->addChild(button_bg);
    Database::getInstancePtr()->gameDatabase.isBgSound = isBgPlay;
    
    CCScaleTo *scale1 = CCScaleTo::create(0.2, 0.6);
    CCScaleTo *scale2 = CCScaleTo::create(0.1, 1.2);
    CCScaleTo *scale3 = CCScaleTo::create(0.1, 1.0);
    
    button_bg->runAction(CCSequence::create(scale1, scale2, scale3, NULL));
}

void Scene_Setting::setEffectSound()
{   
    settingLayer->removeChild(button_effect, true);
    isEffPlay = !isEffPlay;
    SoundManager::muteSoundEffect(isEffPlay);
    
    if(isEffPlay)
    {
        button_effect = ImageManager::getSpriteWithXml2(kImagesheet_setting, "eff_on");
        SoundManager::PlaySoundEffect(sndEffect_energy_1);
    }
    else
        button_effect = ImageManager::getSpriteWithXml2(kImagesheet_setting, "eff_off");
    
    button_effect->setPosition(ccp(220, 345));
    settingLayer->addChild(button_effect);
    Database::getInstancePtr()->gameDatabase.isEffSound = isEffPlay;
    CCScaleTo *scale1 = CCScaleTo::create(0.2, 0.6);
    CCScaleTo *scale2 = CCScaleTo::create(0.1, 1.2);
    CCScaleTo *scale3 = CCScaleTo::create(0.1, 1.0);
    
    button_effect->runAction(CCSequence::create(scale1, scale2, scale3, NULL));
}


void Scene_Setting::ccTouchesBegan(CCSet *touches, CCEvent *event)
{
    CCTouch *touch = (CCTouch*)touches->anyObject();
    CCPoint location = touch->getLocationInView();
    location = CCDirector::sharedDirector()->convertToGL(location);
    
    if(settingState == settingState_init ||
       settingState == settingState_gotoInfo ||
       settingState == settingState_gotoAbout)
        return;
    
    CCPoint _loc = settingLayer->convertToNodeSpace(location);
    switch(settingState)
    {
        case settingState_normal:
            if(Util::makeRectWithSpriteWorldSpace(button_back, this).containsPoint(location))
            {
                SoundManager::PlaySoundEffect(sndEffect_settingButton);
                changeSettingState(settingState_gotoMainmenu);
                CCScaleTo *scale1 = CCScaleTo::create(0.1, 0.8);
                CCScaleTo *scale2 = CCScaleTo::create(0.1, 1.2);
                CCScaleTo *scale3 = CCScaleTo::create(0.1, 1.0);
                button_back->runAction(CCSequence::create(scale1, scale2, scale3, NULL));
            }

            else if(Util::makeRectWithSpriteWorldSpace(button_bg, this).containsPoint(_loc))
                setBgSound();
            else if(Util::makeRectWithSpriteWorldSpace(button_effect, this).containsPoint(_loc))
                setEffectSound();

            else if(Util::makeRectWithSpriteWorldSpace(button_about, this).containsPoint(_loc))
            {
                CCScaleTo *scale1 = CCScaleTo::create(0.1, 0.8);
                CCScaleTo *scale2 = CCScaleTo::create(0.1, 1.2);
                CCScaleTo *scale3 = CCScaleTo::create(0.1, 1.0);
                button_about->runAction(CCSequence::create(scale1, scale2, scale3, NULL));
                
                SoundManager::PlaySoundEffect(sndEffect_settingButton);
                changeSettingState(settingState_gotoAbout);
            }

            else if(Util::makeRectWithSpriteWorldSpace(button_info, this).containsPoint(_loc))
            {
                CCScaleTo *scale1 = CCScaleTo::create(0.1, 0.8);
                CCScaleTo *scale2 = CCScaleTo::create(0.1, 1.2);
                CCScaleTo *scale3 = CCScaleTo::create(0.1, 1.0);
                button_info->runAction(CCSequence::create(scale1, scale2, scale3, NULL));
                
                SoundManager::PlaySoundEffect(sndEffect_settingButton);
                changeSettingState(settingState_gotoInfo);
            }

            else if(Util::makeRectWithSpriteWorldSpace(button_restore, this).containsPoint(_loc))
            {
                CCScaleTo *scale1 = CCScaleTo::create(0.1, 0.8);
                CCScaleTo *scale2 = CCScaleTo::create(0.1, 1.2);
                CCScaleTo *scale3 = CCScaleTo::create(0.1, 1.0);
                button_restore->runAction(CCSequence::create(scale1, scale2, scale3, NULL));
                
                ModuleController::restoreIAP();
                SoundManager::PlaySoundEffect(sndEffect_settingButton);
            }
            break;
        case settingState_about:

            if(Util::makeRectWithSpriteWorldSpace(button_back, this).containsPoint(location))
            {
                SoundManager::PlaySoundEffect(sndEffect_settingButton);
                changeSettingState(settingState_gotoSetting);
                CCScaleTo *scale1 = CCScaleTo::create(0.1, 0.8);
                CCScaleTo *scale2 = CCScaleTo::create(0.1, 1.2);
                CCScaleTo *scale3 = CCScaleTo::create(0.1, 1.0);
                button_back->runAction(CCSequence::create(scale1, scale2, scale3, NULL));
                
            }
            else
            {
                creditMoveLayer->stopAllActions();
            }
            break;
        case settingState_info:
            if(Util::makeRectWithSpriteWorldSpace(button_back, this).containsPoint(location))
            {
                SoundManager::PlaySoundEffect(sndEffect_settingButton);
                changeSettingState(settingState_gotoSetting);
                CCScaleTo *scale1 = CCScaleTo::create(0.1, 0.8);
                CCScaleTo *scale2 = CCScaleTo::create(0.1, 1.2);
                CCScaleTo *scale3 = CCScaleTo::create(0.1, 1.0);
                button_back->runAction(CCSequence::create(scale1, scale2, scale3, NULL));
            }

            else if(Util::makeRectWithSpriteWorldSpace(button_eula, this).containsPoint(location))
                ModuleController::openURL(URL_EULA);
            else if(Util::makeRectWithSpriteWorldSpace(button_privacy, this).containsPoint(location))
                ModuleController::openURL(URL_PRIVACY);
            else if(Util::makeRectWithSpriteWorldSpace(button_terms, this).containsPoint(location))
                ModuleController::openURL(URL_TERMS);
            break;
    }
}


void Scene_Setting::ccTouchesMoved(cocos2d::CCSet* touches, cocos2d::CCEvent* event)
{
    CCTouch *touch = (CCTouch*)touches->anyObject();
    CCPoint location = touch->getLocationInView();
    CCPoint prePoint = touch->getPreviousLocationInView();
    location = CCDirector::sharedDirector()->convertToGL(location);
    prePoint = CCDirector::sharedDirector()->convertToGL(prePoint);
    
    switch(settingState)
    {
        case settingState_about:
            creditMoveLayer->setPosition(ccp(0, MAX(0, creditMoveLayer->getPosition().y + (location.y - prePoint.y))));
            break;
            
    }
}

void Scene_Setting::ccTouchesEnded(cocos2d::CCSet* touches, cocos2d::CCEvent* event)
{
    switch(settingState)
    {
        case settingState_about:
            CCMoveBy *move = CCMoveBy::create(1, ccp(0, 30 * ModuleController::getImageScale()));
            creditMoveLayer->runAction(CCRepeatForever::create(move));
            break;
    }
}


void Scene_Setting::changeSettingState(int state)
{
    settingState = state;
    switch (settingState) {
        case settingState_init:
            settingLayer->setVisible(true);
            creditsLayer->setVisible(false);
            infoLayer->setVisible(false);
            
            if(FadeActionLayer::getInstancePtr()->getFadeOuntFlg())
                FadeActionLayer::getInstancePtr()->startFadeIn();
            break;
        case settingState_gotoMainmenu:
            Database::getInstancePtr()->save();
            FadeActionLayer::getInstancePtr()->startFadeOut(false);
            break;
        case settingState_gotoAbout:
        {
            creditMoveLayer->setPosition(ccp(0, winSize.height - 100));
            FadeActionLayer::getInstancePtr()->startFadeOut(false);
        }
            break;
        case settingState_gotoInfo:
            FadeActionLayer::getInstancePtr()->startFadeOut(false);
            break;
        case settingState_about:
        {
            settingLayer->setVisible(false);
            creditsLayer->setVisible(true);
            FadeActionLayer::getInstancePtr()->startFadeIn();
            CCMoveBy *move = CCMoveBy::create(1, ccp(0, 30 * ModuleController::getImageScale()));
            creditMoveLayer->runAction(CCRepeatForever::create(move));
        }
            break;
        case settingState_info:
            settingLayer->setVisible(false);
            infoLayer->setVisible(true);
            FadeActionLayer::getInstancePtr()->startFadeIn();
            break;
        case settingState_gotoSetting:
            FadeActionLayer::getInstancePtr()->startFadeOut(false);
            break;
    }
}

void Scene_Setting::callback_restore()
{
    for(int i = 1; i < MAX_CHAPTER; i++)
        Database::getInstancePtr()->gameDatabase.chapterOpenFlg[i] = true;
    Database::getInstancePtr()->save();
    CCLog("restore");
}